package com.google.code.sysarch.v2;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class SantaPanel extends JPanel {

	public BufferedImage SantaImage = null;
	public BufferedImage ElfImage = null;
	public BufferedImage HutchImage = null;
	public BufferedImage NorthpoleImage = null;
	public BufferedImage ReindeerImage = null;
	public BufferedImage ToystoreImage = null;
	
	public final int NorthpoleX = 0;
	public final int NorthpoleY = 0;
	public int SantaX = 255;
	public int SantaY = 5;
	
	public final static int HutchX = 460;
	public final static int HutchY = 380;
	
	public final static int ToystoreX = 0;
	public final static int ToystoreY = 480;
	
	
	/**
	 * constructor for our custom panel
	 */
	SantaPanel() {
		super();
		loadGFX();
	}
	

	/**
	 * loads all GFX needed for this frame
	 * 
	 */
	public void loadGFX() {
		String myPath = Main.class.getProtectionDomain().getCodeSource().getLocation().toString();	// /Users/peter/Documents/workspace/SysArch/bin/
		myPath += Main.RELATIVE_PATH_FROM_BIN_TO_SRC;
		myPath = (String) myPath.subSequence(myPath.indexOf(":") + 1, myPath.length());
		try {
			this.SantaImage = ImageIO.read(new File(myPath + "Santa.png"));
			this.ElfImage = ImageIO.read(new File(myPath + "Elf.png"));
			this.HutchImage = ImageIO.read(new File(myPath + "Hutch.jpg"));
			this.NorthpoleImage = ImageIO.read(new File(myPath + "Northpole.jpg"));
			this.ReindeerImage = ImageIO.read(new File(myPath + "Reindeer.png"));
			this.ToystoreImage = ImageIO.read(new File(myPath + "Toystore.jpg"));
			
		} catch (IOException e) {
			System.out.println("unable to load graphics!");
			System.out.println("path to gfx: " + myPath);
			//e.printStackTrace();
		}
	}
	
	
	/**
	 * this method paints all images that we need
	 */
	public void paint(Graphics g) {
	    super.paint(g);
	    
	    // draw background
	    g.setColor(Color.WHITE);
	    g.fillRect(0, 0, SantaFrame.FrameWidth, SantaFrame.FrameHeight);
	    
	    // draw landscape
	    g.drawImage(this.NorthpoleImage, NorthpoleX, NorthpoleY, null);
	    g.drawImage(this.HutchImage, HutchX, HutchY, null);
	    g.drawImage(this.ToystoreImage, ToystoreX, ToystoreY, null);
	    
	    // draw santa
	    g.drawImage(this.SantaImage, SantaX, SantaY, null);
	    
	    // draw reindeers
	    for (int i = 0; i < Main.MyReindeers.length; i++) {
	    	g.drawImage(this.ReindeerImage, Main.MyReindeers[i].posX, Main.MyReindeers[i].posY, null);
	    }

	    // draw elfs
	    for (int i = 0; i < Main.MyElfs.length; i++) {
	    	g.drawImage(this.ElfImage, Main.MyElfs[i].posX, Main.MyElfs[i].posY, null);
	    }
}


}
